﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CW3DGraphLib;
using System.IO.Ports;
using WFNetLib;

namespace RobotControl
{
    public partial class Form_Main : Form
    {
        private delegate void delegateChangeParamList(ParamsListAddr Addr, string value);
        public static double sdHX;
        private void ChangeParamList(ParamsListAddr Addr, string value)
        {
            ParamList.Items[(int)Addr].SubItems[1].Text = value;
            if (Addr == ParamsListAddr.航向)
            {
                meter1.Value = Convert.ToDouble(value);
                sdHX = meter1.Value;
                if (定向)
                {
                    HeadingPIDControl(meter1.Value);
                }
            }
            if (!bSave)
            {
                robotData.SetCurData(Addr, value);
            }
        }
        public void ExternChangeParamList(ParamsListAddr Addr, string value)
        {
            this.Invoke(new delegateChangeParamList(ChangeParamList), Addr, value);
        }

        private delegate void delegateAddText(string str);
        private void AddText(string str)
        {
            DateTime dt = DateTime.Now;
            if (tbLog.TextLength > tbLog.MaxLength - 1000)
                tbLog.Clear();
            tbLog.AppendText("------" + dt.ToString() + "------" + "\r\n");
            tbLog.AppendText(str + "\r\n");
        }
        public void ExternAddText(string str)
        {
            this.Invoke(new delegateAddText(AddText), str);
        }

        private delegate void delegateGraph3D(double[] x,double[] y,double[] z);
        private void Graph3D(double[] x, double[] y, double[] z)
        {
            axCWGraph3D1.Plot3DCurve(x, y, z);
            CWCursor3D cur = axCWGraph3D1.Cursors.Item("当前位置");
            cur.XPosition = x[x.Length - 1];
            cur.YPosition = y[y.Length - 1];
            cur.ZPosition = z[z.Length - 1];
        }
        public void ExternGraph3D(double[] x, double[] y, double[] z)
        {
            this.Invoke(new delegateGraph3D(Graph3D),x,y,z);
        }
    }
}
